from qqbot import QQBotSlot as qqbotslot, RunBot
from qqbot import qqbotsched
import requests
import json
import subprocess
grouplist = ['【法联】全岛法师协会','欧皇管理员','机器人学习群']


def getRobotinfo(msg):
	url = f"http://www.tuling123.com/openapi/api?key=8b8701ff97cf4156bd3a7996f9948f2f&info={msg}"
	resp = requests.get(url)
	myjson = json.loads(resp.text)
	return myjson['text']
# print([member,member.name])
# print([contact, type(contact), contact.qq, contact.name, contact.uin, contact.mark])

@qqbotslot
def onQQMessage(bot, contact, member, content):
	# if contact.ctype == 'group':
	# 	if contact.name in grouplist:
	# 		if bot.isMe(contact,member):
	# 			print('自己再发')
	# 		else:
	# 			if content:
	# 				robot = getRobotinfo(content)
	# 				bot.SendTo(contact,robot)

	if contact.ctype == 'group':
		print([member,member.name])
		print([contact, type(contact), contact.qq, contact.name, contact.uin, contact.mark])
		if contact.name in '机器人学习群':
			if bot.isMe(contact,member):
				print('自己再发')
			else:
				if content == '我要禁言':
					print([member,member.name])
					print([contact, type(contact), contact.qq, contact.name, contact.uin, contact.mark])
					bot.SendTo(contact,'禁言')
					child = subprocess.Popen(f'qq group-shut {contact.name} {member.name} 60',shell=True)

	if contact.ctype == 'buddy':
		if content == '-stop hyh':
			bot.SendTo(contact,'qq机器人已关闭')
			bot.Stop()

@qqbotsched(hour='15', minute='05')
def mytask(bot):
	gl = bot.List('group', '欧皇管理员')
	if gl is not None:
		for group in gl:
			bot.SendTo(group, '表弟们，开团了，表哥已经上线')

if __name__ == '__main__':
	RunBot()

